import uviewPlus from '@/uni_modules/uview-plus'
import httpInterceptor from '@/common/utils/http.interceptor.js'
import $store, {
	setupPinia
} from '@/common/store/index.js';
import $config from '@/common/config.js'
import * as $tools from '@/common/utils/tool.js'
import {
	createSSRApp
} from 'vue'

const initUse = (app) => {

	// @/common/config.js 属性挂载到全局
	setGlobalProperties(app, $config)
	// @/common/config.js 属性挂载到uni
	setGlobalProperties({config: {globalProperties: uni}}, $config)

	// @/common/utils/tool.js 属性挂载到全局
	setGlobalProperties(app, $tools)
	// @/common/utils/tool.js 属性挂载到uni
	setGlobalProperties({config: {globalProperties: uni}}, $tools)

	//store 属性挂载到全局
	setupPinia(app)
	setGlobalProperties(app, {$store})
	//store 属性挂载到uni
	uni.$store = $store

	//uview-plus
	app.use(uviewPlus)
	//接口拦截
	app.use(httpInterceptor, app)

	console.warn('VUE_VERSION:', app.version, '  U_VIEW_PLUS:', uni.$u.config.v)
}
const COMMON = {
	initUse,
	$store,
	$config
}
// #ifdef H5
if ($config.$NODE_ENV != 'production') {
	// #ifdef H5
	// import("vconsole").then(vConsole => {
	// 	new vConsole.default()
	// })
	// #endif
	
}
// #endif

function setGlobalProperties(app, configs) {
	let keys = Object.keys(configs)
	for (let key of keys) {
		app.config.globalProperties[key] = configs[key]
	}
}
export default COMMON